sele notass  
        if .not. impressora()
           retu
        endif
        mrascunho = ' '
        while .t.
         legal(8,4,22,77,'Nota Fiscal - Modelo novo')
         sele notass  
         mnota = 0
         @ 10,6  say 'Nota-Fiscal   :' get mnota     pict '999999'
         @ 10,40 say 'Rascunho      :' get mrascunho pict '!'             
         read
         if empty(mnota)
            exit
         endif
         seek mnota
         if eof()
            mensa(10,'Nota fiscal nao cadastrada',2)
            loop
         endif
         if impressa = 'Y'
            mensa(10,'Nota fiscal ja impressa',2)
            loop
         endif
         inicializa()
         sele clientes
         seek mcliente
         mnome     = nome
         mpublico  = publico
         mretiss   = retiss
         @ 11,6  say 'Cliente       : ' + strzero(mcliente,6) + ' ' + mnome
         @ 12,6  say 'Data Emissao  : ' + dtoc(memissao)
         @ 12,40 say 'Vencimento    : ' + dtoc(mvencto)
         if .not. confirma(18,60,' 1 - Confirma ',' 2 - Cancela  ')
            exit
         endif
         sele notass
         if mrascunho = 'N'
            repla impressa with 'S'
         endif
         set devi to printer
         setprc(0,0)
         sele clientes                                      
         @ prow()+1,2  say chr(18)
         @ prow()+1,72 say strzero(mnota,6)
         @ prow()  ,72 say strzero(mnota,6)
         @ prow()  ,72 say strzero(mnota,6)
         @ prow()+2,46 say 'XX'
         @ prow()+1,20 say chr(15)
         sele carimbo
         @ prow()+6,44 say carimbos
         @ prow()  ,44 say carimbos
         sele clientes
         @ prow()+1,20 say chr(18)
         @ prow()+1 ,4 say nome + str(mcliente,9)
         @ prow()   ,4 say nome                                    
         @ prow()   ,4 say nome                                    
         @ prow()+2,4  say endereco
         @ prow()+2,4  say cidade + '            ' + uf
         @ prow()+2,4  say trans(cgc,'@R 99.999.999/9999-99') + space(22) + inscricao 
         @ prow(),67   say memissao
         @ prow()+4,4  say ''
         sele itemsegu
         seek mnota
         for x = 1 to 12
             if alltrim(descricao) = '.'
                @ prow()+1,0 say ''
                skip
                loop
             endif
             if .not. empty(descricao)
                 @ prow()+1,12 say descricao
             endif
             if unitario # 0      
                @ prow(),52 say unitario pict '9,999,999.99'
             endif
             if valor # 0
                @ prow(),66  say valor   pict '9,999,999.99'
             endif
             skip
         next
         sele notass
         if miss > 0
            @ prow()+2,12 say 'I.S.S.' + space(33) + trans(maliqiss,'99') + ' %'
         endif
         @ prow()+1,2 say chr(15)
         if mretencao1 # 0
            sele retencao
            seek mretencao1
            mtemp = mtotal - (mvaletransp + mvalealimen + mvmaterial)
            @ prow()+1,20 say 'Base de Calculo - Seguridade Social...............  ' + trans(mtemp,'9,999,999.99')
            if (mvaletransp + mvalealimen + mvmaterial) > 0
               mtempl = ''
               if mvaletransp > 0
                  mtempl  = 'Transporte :' + trans(mvaletransp,'99,999.99')
               endif
               if mvalealimen > 0
                  mtempl += ' Alimentacao :' + trans(mvalealimen,'99,999.99')
               endif
               if mvmaterial > 0 
                  mtempl += ' Material :' + trans(mvmaterial,'99,999.99')
               endif
               @ prow()+1,20 say mtempl 
            endif
            @ prow()+1,20 say linha1
            @ prow()+if(len(alltrim(linha2)) # 0,1,0),20 say linha2 
            @ prow(),70 say ' R$ ' + trans(mvalorret1,'999,999.99')
         endif
         sele notass
         if mretencao2 # 0
            sele retencao
            seek mretencao2
            @ prow()+2,20 say linha1
            @ prow()+if(len(alltrim(linha2)) # 0,1,0),20 say linha2 
            @ prow(),70 say ' R$ ' + trans(mvalorret2,'999,999.99')
         endif
         if mretencao3 # 0
            sele retencao
            seek mretencao3
            @ prow()+2,20 say linha1
            @ prow()+if(len(alltrim(linha2)) # 0,1,0),20 say linha2 
            @ prow(),70 say ' R$ ' + trans(mvalorret3,'999,999.99')
         endif
         mliquido = mtotal - (mvalorret1 + mvalorret2 + mvalorret3 + mfederal)
         sele notass
         if mretiss = 'S'
            mliquido -= iss
         endif
         mtemp    = mirrf + mcsll + mcofins + mpis
         if mtemp > 0
            mtirrf   = mtotal * (mirrf/100)
            mtcsll   = mtotal * (mcsll/100)
            mtcofins = mtotal * (mcofins/100)
            mtpis    = mtotal * (mpis/100)
            @ prow()+2,35 say 'Retencao Referente aos Tributos Federais'
            if mirrf # 0
               @ prow()+1,20 say 'IRRF      ' + space(31) + trans(mirrf,'99.99')   + '   R$ ' + trans(mtirrf,'9,999,999.99')
            endif
            if mcsll # 0
               @ prow()+1,20 say 'CSLL      ' + space(31) + trans(mcsll,'99.99')   + '   R$ ' + trans(mtcsll,'9,999,999.99')
            endif
            @ prow()+1,20 say 'COFINS    ' + space(31) + trans(mcofins,'99.99') + '   R$ ' + trans(mtcofins,'9,999,999.99')
            @ prow()+1,20 say 'PIS/PASEP ' + space(31) + trans(mpis,'99.99')    + '   R$ ' + trans(mtpis,'9,999,999.99')
            @ prow()+1,20 say 'TOTAL     ' + space(31) + trans(mtemp,'99.99')   + '   R$ ' + trans(mfederal,'9,999,999.99')
            @ prow()+1,32 say 'IN/SRF No. 539, de 25 de Abril de 2005.'
         else  
            @ prow()+2,20 say 'Valor Liquido.....................................  ' + trans(mliquido,'9,999,999.99')
         endif
         @ prow()+1,2 say chr(18)
         if .not. empty(mvencto)
            @ prow()+2,18 say 'Vencimento : ' + dtoc(mvencto)
         endif
         monde = 50-prow()  
         @ prow()+monde,70 say ''  //  prow() pict '99999'
         @ prow()+2,66     say mtotal pict '9,999,999.99'
         @ prow()+2,28     say mtotal pict '9,999,999.99'
         miss = mtotal * (maliqiss/100)
         @ prow(),68   say miss   pict '999,999.99'
         if mbanco # 0 .and. mbanco # 99
            sele bancos   
            seek mbanco     
            @ prow()+3,12 say nome + 'Agencia : ' + alltrim(agencia) + '  C/C : ' + conta
            @ prow(),12   say nome + 'Agencia : ' + alltrim(agencia) + '  C/C : ' + conta
            @ prow(),12   say nome + 'Agencia : ' + alltrim(agencia) + '  C/C : ' + conta
         else  
            @ prow()+3,12 say ''
         endif 
         @ prow()+5,72 say strzero(mnota,6)
         @ prow()  ,72 say strzero(mnota,6)
         @ prow()  ,72 say strzero(mnota,6)
         @ prow()+4,0  say ''      
         setprc(0,0)
         set devi to screen
        enddo
        sele notass
        skip
        retu(2)
   
